from research.calcor import calcor_base

class MAlongshort(calcor_base):
    def __init__(self,timeperiod=2,ma=[],flags=[1,-1]):
        super().__init__(timeperiod=timeperiod,datatype="dimn",inputs=len(ma))
        self.flags=flags
    def calc(self):
        rst=None
        islong=True
        for data in self.hisdata:
            b=data[-1]
            preb=data[0]
            if b<preb:
                islong=False
                break
        isshort=True
        for data in self.hisdata:
            b = data[-1]
            preb = data[0]
            if b > preb:
                isshort=False
                break
        if islong:
            rst= self.flags[0]
        if isshort:
            rst=self.flags[1]
        return rst